package com.ophiux.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ophiux.common.core.base.Result;
import com.ophiux.order.service.IOrderService;
import com.ophiux.order.model.dto.ProductOrderDTO;
import com.ophiux.order.model.vo.ProductOrderAddVo;
import com.ophiux.order.model.vo.ProductOrderQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@Api(tags = "产品订单接口")
public class OrderController {
	
    @Autowired
    IOrderService orderService;

	@ApiOperation("1.列表记录")
    @GetMapping
    public Result<IPage<ProductOrderDTO>> list(@RequestParam(required = false, defaultValue = "1") Integer current,
                                               @RequestParam(required = false, defaultValue = "10") Integer size, ProductOrderQueryVo queryDTO) {
		IPage<ProductOrderDTO> page = orderService.getPage(new Page<>(current, size), queryDTO);
		return Result.success(page);
    }

	@ApiOperation("2.新增产品订单")
	@PostMapping("/add")
	public Result add(@RequestBody ProductOrderAddVo vo) {
		return orderService.insert(vo);
	}
	
	@Value("${seata.enabled}")
	String param;

    @GetMapping("/getOrder")
    public String getOrder() {
    	return "订单号:1314520=========="+param;
    }


    //  http://localhost:9200/order/createOrder
    @GetMapping("/createOrder")
    public String createOrder(Integer amount,boolean isException){
	    return orderService.createOrder(amount,isException);
    }

}
